import type { PageList, ResponseStruct } from '#/global'
import { CourseVo } from './manage';

export type TaskableType =  'task_image_text' | 'task_micro_course' | 'task_practice' | 'task_word' | 'task_live' | 'task_data_download' | 'task_video_slicing';
export interface CourseTaskVo {
  id?:number;
  name?: string;
  course_id?: number;
  course?: CourseVo
  section_id?: number;
  is_publish?: number;
  creator_id?: number;
  taskable_type?:TaskableType;
  taskable_id?: number;
  taskable?: any;
}

export interface CourseTaskSearchVo {
  name?: string;
  course_id?: number;
  section_id?: number;
  is_publish?: number;
}

export function page(data: CourseTaskSearchVo): Promise<ResponseStruct<PageList<CourseTaskVo>>> {
  return useHttp().get('/admin/course-task', { params: data })
}

export function create(data: CourseTaskVo): Promise<ResponseStruct<null>> {
  return useHttp().post('/admin/course-task', data)
}

export function save(id: number, data: CourseTaskVo): Promise<ResponseStruct<null>> {
  return useHttp().put(`/admin/course-task/${id}`, data)
}

export function deleteByIds(ids: number[]): Promise<ResponseStruct<null>> {
  return useHttp().delete('/admin/course-task', { data: ids })
}

export function all(params = {}): Promise<ResponseStruct<CourseTaskVo[]>> {
  return useHttp().get('/admin/course-task/all', { params })
}
